

#include "History.h"
#include "assert.h"
#include <qlistbox.h>
#include <qtextstream.h>
#include <qpushbutton.h>
#include <qtextcodec.h>



History::History(QWidget* parent, const char* name, bool modal, WFlags fl, int id ) : HistoryDialog(parent, name, modal, fl), m_id(id)
{
	QString historyFileName[] = {(tr("/history0.dat")),(tr("/history1.dat")), (tr("/history2.dat"))};
	m_historyFile = new QFile(historyFileName[m_id]);
	assert(m_historyFile);
	bool isOk = m_historyFile->open(IO_ReadWrite);
	assert(isOk);



}


History::~History()
{
	delete m_historyFile;
}


void History::carHappen(const QString& str)
{
		historyListBox->insertItem(str);

		QTextStream text(m_historyFile);
		text << str;
		text << endl;
}


int History::loadFile()
{
	QString str;
	QTextStream text(m_historyFile);

	while(true)
	{
		str = text.readLine();
		if(str.isNull())
		{
			break;
		}
		if(!str.isEmpty())
		{

		historyListBox->insertItem(str);
		}
	}

	return 0;
}


